Array.prototype.getReader = function(){
    if(!this) return;
    var that = this;
    var currenIndex = 0;
    return {
        read : function(n=1){
            if(typeof n !== 'number' || n%1 !== 0 || n<=0){
                console.log('Error');
            } else{
                // console.log(arr.splice(0,n));
                console.log(that.slice(currenIndex,n+currenIndex));
                currenIndex += n;
            }
        }
    }
};

function f1(){
    var currenIndex = 0;
    var arr = [1,2,3,4,5];
    return function(n=1){
        if(typeof n !== 'number' || n%1 !== 0 || n<=0) console.log('Error');
        // console.log(arr.splice(0,n));
        console.log(arr.slice(currenIndex,n+currenIndex));
        currenIndex += n;
    }
}
const arr = [1,2,3,4,5];
var reader = arr.getReader();
console.log(reader);
reader.read();
reader.read(1);
reader.read(2);
reader.read(2);
reader.read();
reader.read();
// [].getReader().read([]);

